﻿using Model.BusinessModel.OutPut;

namespace CoreDomain
{
    /// <summary>
    /// 树核心
    /// </summary>
    public static class TreeCore
    {
        /// <summary>
        /// 添加树节点
        /// </summary>
        /// <param name="sourceTree">原始树</param>
        /// <param name="addNode">新增节点</param>
        public static void AddTreeNode(List<TreeOutPut> sourceTree, TreeOutPut addNode)
        {
            var children = sourceTree.Where(x => x.key == addNode.pKey).ToList();

            if (children.Count > 0)
            {
                children[0].children.Add(addNode);
            }
            else
            {
                foreach (var child in sourceTree)
                {
                    AddTreeNode(child.children, addNode);
                }
            }
        }
    }
}
